import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'

// 导入全局样式
import './assets/styles/main.scss'

const app = createApp(App)

// 使用插件（先创建 pinia 实例，便于初始化用户状态）
const pinia = createPinia()
app.use(pinia)
app.use(router)

// 初始化登录态：从 local/sessionStorage 恢复
import { useUserStore } from './stores/user'
const userStore = useUserStore(pinia)
userStore.initUser()

// 初始化购物车：从 localStorage 恢复
import { useCartStore } from './stores/cart'
const cartStore = useCartStore(pinia)
cartStore.initCart()

// 全局指令：图片懒加载
import lazy from './directives/lazy'
app.directive('lazy', lazy)

// 挂载应用
app.mount('#app')
